<?php
	class Shop
	{
		private $stocks=array();
		public $sum=0;
		private $bank;
		private $name;
		
		public function addStock($stock)
		{
			$this->stocks[$stock->getStockName()]=$stock;
		}
		
		
		public function setShopBank($bank)
		{
			$this->bank=$bank;
		}
		
		public function setShopName($name)
		{
			$this->name=$name;	
		}
		
		public function getShopStock()
		{
			return $this->stocks;
		}
		
		public function getShopSum()
		{
			return $this->sum;
		}
		
		public function getShopBank()
		{
			return $this->bank;
		}
		
		public function getShopName()
		{
			return $this->name;
		}
		
		public function sellStock($name, $iban, $quantity)
		{
			if(!array_key_exists($name, $this->stocks))
			{
				echo "No such stock in the shop<br>";
			}
			else 
			{
				$stock=$this->stocks[$name];
				$bank=$this->getShopBank();
				$profit=$stock->getStockPrice()*$quantity;
				
				if($quantity>$stock->getStockQuantity())
				{
					echo "Not enough of this stock in the shop.<br>";
				}
				elseif (!array_key_exists($iban, $bank->getAll())) 
				{
					echo "No such account in this bank!<br>";
				}
				elseif($bank->getAccount($iban)->getAccMoney()<$profit) 
				{
					echo "Not enough money in the account!";
				}
				else
				{
					$this->sum+=$profit;
					$kg=$stock->getStockQuantity();
					$stock->setStockQuantity($kg-$quantity);
					$this->getShopBank()->withdraw($iban,$profit);
				}
			}
		}
		
	};
?>